import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('cart', () => {
  let cart=ref([])
  function pinina(detail,goods_id){
    let pd=cart.value.find(item=>item.goods.goods_id==goods_id)
    if(pd){
      pd.number++
    }
    else{
      cart.value.push({
        username:localStorage.getItem('username'),
        id:Math.floor(Math.random()*1000000),
        goods:detail,
        number:1,
        checked:false,
      })
    }

  }
 

  return {cart,pinina }
},
 {
    persist: true,
  },
)
